package cn.xie.wrench.ty.wrench.starter.dynamic.config.center.listern;

import cn.xie.wrench.ty.wrench.starter.dynamic.config.center.domin.model.AttributeVO;
import cn.xie.wrench.ty.wrench.starter.dynamic.config.center.domin.service.IDynamicConfigCenterService;
import org.redisson.api.listener.MessageListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author: xiaoxie
 * create: 2025-05-14 11:13
 * @BelongsProject: ty-wrench
 * @BelongsPackage: cn.xie.wrench.ty.wrench.starter.dynamic.config.center.listern
 * description:
 */
public class DynamicConfigCenterAdjustListener implements MessageListener<AttributeVO> {

    private final Logger log = LoggerFactory.getLogger(DynamicConfigCenterAdjustListener.class);

    private final IDynamicConfigCenterService dynamicConfigCenterService;

    public DynamicConfigCenterAdjustListener(IDynamicConfigCenterService dynamicConfigCenterService) {
        this.dynamicConfigCenterService = dynamicConfigCenterService;
    }

    @Override
    public void onMessage(CharSequence charSequence, AttributeVO attributeVO) {
        try {
            log.info("xfg-wrench dcc config attribute:{} value:{}", attributeVO.getAttribute(), attributeVO.getValue());
            dynamicConfigCenterService.adjustAttributeValue(attributeVO);
        } catch (Exception e) {
            log.error("xfg-wrench dcc config attribute:{} value:{}", attributeVO.getAttribute(), attributeVO.getValue(), e);
        }
    }

}
